package beanstao.util.log;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * 针对Log4j的一些扩展方法
 * @author beanstao@google.com 
 * 
 */
public class LogHelper
{

	public static void init(String propertyFile)
	{
		PropertyConfigurator.configure(propertyFile);
	}

	/**
	 * 获得当前类对应的Logger
	 * @return
	 */
	public static Logger getCurrentLogger()
	{
		StackTraceElement[] ste = new Throwable().getStackTrace();
		Logger logger = Logger.getLogger(ste[1].getClassName());
		return logger;
	}

	private static Logger logger(Object obj)
	{
		return Logger.getLogger(obj.getClass().getName());
	}

	public static void logDebug(Object obj, Object message)
	{
		logger(obj).debug(message);
	}

	public static void logDebug(Object obj, Object message, Throwable t)
	{
		logger(obj).debug(message, t);
	}

	public static void logError(Object obj, Object message)
	{
		logger(obj).error(message);
	}

	public static void logError(Object obj, Object message, Throwable t)
	{
		logger(obj).error(message, t);
	}

	public static void logFatal(Object obj, Object message)
	{
		logger(obj).fatal(message);
	}

	public static void logFatal(Object obj, Object message, Throwable t)
	{
		logger(obj).fatal(message, t);
	}

	public static void logInfo(Object obj, Object message)
	{
		logger(obj).info(message);
	}

	public static void logInfo(Object obj, Object message, Throwable t)
	{
		logger(obj).info(message, t);
	}

	public static void logTrace(Object obj, Object message)
	{
		logger(obj).trace(message);
	}

	public static void logTrace(Object obj, Object message, Throwable t)
	{
		logger(obj).trace(message, t);
	}

	public static void logWarn(Object obj, Object message)
	{
		logger(obj).warn(message);
	}

	public static void logWarn(Object obj, Object message, Throwable t)
	{
		logger(obj).warn(message, t);
	}

}
